package com.hqbzl.chat.handler;

import com.hqbzl.chat.factory.Factory;
import com.hqbzl.chat.model.PingRequestMessage;
import com.hqbzl.chat.model.PingResponseMessage;
import com.hqbzl.chat.model.ResponseMessage;
import com.hqbzl.chat.model.SendMessage;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Sharable
public final class PingRequestHandler extends SimpleChannelInboundHandler<PingRequestMessage> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, PingRequestMessage msg) throws Exception {
        final String ping = msg.getMsg();
        log.debug("ping msg: {}", ping);
        ctx.writeAndFlush(new PingResponseMessage());
    }
}